$(function () {
    $('#submitURLModal').on('show.bs.modal', function(e) {
        var $me = $(e.relatedTarget)
        $('#requestAdd').data('id',$me.data('id'));
        $('#requestInterfaceName').val($me.data('name'));
    }); 
    $('#requestAdd').on('click', function (e) {
        e.preventDefault();
        var submitBtn = $(this);
        var params = {};
        params.hotel = window.currentHotel;
        params.url = $('#requestURL').val();
        params.serverId = submitBtn.data('id');
        ajaxRequest('/Home/InterfaceServer/applyServer', params, 'post',null, function(error) {
            if (error.responseJSON === undefined) {
                formInlineTip(submitBtn, lang('tip.server'));
            } else {
                formInlineTip(submitBtn, error.responseJSON.info);
            }
            refreshVcode();
            submitBtn.removeAttr('disabled');
        }, submitBtn);
    });
    //修改url
    $('#editURLModal').on('show.bs.modal', function(e) {
        var $me = $(e.relatedTarget)
        $('#requestEdit').data('id',$me.data('id'));
        $('#requestEditURL').val($me.data('url'));
    }); 
    $('#requestEdit').on('click', function (e) {
        e.preventDefault();
        var submitBtn = $(this);
        var params = {};
        params.hotel = window.currentHotel;
        params.url = $('#requestEditURL').val();
        params.serverId = submitBtn.data('id');
        ajaxRequest('/Home/InterfaceServer/setApplyInfo', params, 'post',null, function(error) {
            if (error.responseJSON === undefined) {
                formInlineTip(submitBtn, lang('tip.server'));
            } else {
                formInlineTip(submitBtn, error.responseJSON.info);
            }
            refreshVcode();
            submitBtn.removeAttr('disabled');
        }, submitBtn);
    });    
    //重置
    $('#doc-center').on('click','.reseturl',function(e){
        e.preventDefault();
        var submitBtn = $(this);
        var params = {};
        params.hotel = window.currentHotel;
        params.url = submitBtn.data('url');
        params.serverId = submitBtn.data('id');  
        params.token = 1;        
        ajaxRequest('/Home/InterfaceServer/setApplyInfo', params, 'post',function(data){
            submitBtn.prev('span').text(data.data.token);
        },null);
    });
    $('#server-agreement').on('click',function(){
        var checkbox = $(this).closest('.checkbox');
        if(checkbox.hasClass('is-checked')){
            $('#requestAdd').attr('disabled',true);
        }else{
            $('#requestAdd').removeAttr('disabled');
        };
    });
});